ajax({
  url: "/sa/foodDet.json",
  success: function (res) {
    res = JSON.parse(res);
    con.innerHTML = render(res.data.cake);
    if(location.hash){
       var nong = document.querySelector("#nong");
    nong.setAttribute("href", location.hash);
    nong.click();
    }
   
  },
});
var con = document.querySelector(".con");
function render(data) {
  return data
    .map(function (item) {
      return `<div class="con1">
        <div class="tup">
            <img src="${item.img}" id="a${item.id}" alt="">
        </div>
        <div class="qiao">
            <h4>${item.name}</h4>
            <p class="kel">${item.cont}</p>
        </div>
        <div class="wenzi">
            ${fun(item.neirong)}
        </div>
    </div>`;
    })
    .join("");
}
function fun(dt) {
  return dt
    .map(function (items) {
      return `<p>${items}</p>`;
    })
    .join("");
}

// 回到顶部
var dingbu = document.querySelector(".dingbu");
window.onscroll = function () {
  var height = window.innerHeight + scrollY;
  if (height > window.innerHeight) {
    dingbu.style.display = "block";
    dingbu.onclick = function () {
      scrollTo({ top: 0, behavior: "smooth" });
    };
  } else {
    dingbu.style.display = "none";
  }
};
